package com.goods.controller.business;

import com.goods.business.service.InStockService;
import com.goods.common.error.BusinessException;
import com.goods.common.response.ResponseBean;
import com.goods.common.utils.JWTUtils;
import com.goods.common.vo.business.InStockDetailVO;
import com.goods.common.vo.business.InStockItemVO;
import com.goods.common.vo.business.InStockVO;
import com.goods.common.vo.system.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @Description: 入库记录
 * @Author: Mr.Cao
 * @DateTime: 2021/11/10 0:41
 * BMW F750GS
 **/
@RestController
@RequestMapping("business/inStock/")
public class InStockController {
    @Autowired
    private InStockService inStockService;

    /**
     * 分页查询入库记录
     * */
    //http://www.localhost:8989/business/inStock/findInStockList?pageNum=1&pageSize=10&status=0
    @GetMapping("findInStockList")
    public ResponseBean findInStockList(@RequestParam Map queryMap){
      PageVO pageVO =  inStockService.findInStockList(queryMap);
        return ResponseBean.success(pageVO);
    }
    /**
     * 新建入库记录
     * */
    //http://www.localhost:8989/business/inStock/addIntoStock
    @PostMapping("addIntoStock")
    public ResponseBean addIntoStock(@RequestBody InStockVO inStockVO, HttpServletRequest request){

        System.out.println("inStockVO = " + inStockVO.toString());
        inStockService.addIntoStock(inStockVO,request);
        return ResponseBean.success();
    }
    /**
     * 查看入库记录明细
     * */
    //http://www.localhost:8989/business/inStock/detail/111?pageNum=1
    @GetMapping("detail/{id}")
    public ResponseBean detail(@PathVariable long id,Integer pageNum){
      InStockDetailVO inStockDetailVO =  inStockService.detail(id,pageNum);
        return ResponseBean.success(inStockDetailVO);
    }
    /**
     * 审核通过
     * */
    //http://www.localhost:8989/business/inStock/publish/113
    @PutMapping("publish/{id}")
    public ResponseBean publish(@PathVariable long id) throws BusinessException {
        inStockService.publish(id);
        return ResponseBean.success();
    }
    /**
     * 审核不通过,删除
     * */
    //http://www.localhost:8989/business/inStock/delete/113
    @GetMapping("delete/{id}")
    public ResponseBean delete(@PathVariable long id){
        inStockService.delete(id);
        return ResponseBean.success();
    }
    /**
     * 移除进入回收站
     * */
    //http://www.localhost:8989/business/inStock/remove/111
    @PutMapping("remove/{id}")
    public ResponseBean remove(@PathVariable long id){
        inStockService.remove(id);
        return ResponseBean.success();
    }
    /**
     * 还原: 恢复到正常
     * */
    //http://www.localhost:8989/business/inStock/back/115
    @PutMapping("back/{id}")
    public ResponseBean back(@PathVariable long id){
        inStockService.back(id);
        return ResponseBean.success();
    }
}
